package acwing._2LanQiao._12No12;
/**
 * @Project : AlgorithmLearning
 * @Package : ACWing._2LanQiao._12No12
 * @File : Q3492.java
 * @Author : WangRuoyu
 * @Date : 2023/3/30 14:53
 */

import java.io.*;
import java.util.ArrayList;

// 二分 快读快写可以ac
public class Q3492 {
    static ArrayList<int[]> list = new ArrayList<>();

    static int bSearch(int x) {
        int l = 0;
        int r = list.size() - 1;

        while (l < r) {
            int mid = (l + r + 1) / 2;
            if (list.get(mid)[0] <= x) {
                l = mid;
            } else {
                r = mid - 1;
            }
        }

        return l;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] words = br.readLine().split(" ");
        int n = Integer.parseInt(words[0]);
        int m = Integer.parseInt(words[1]);
        list = new ArrayList<>();

        int[] computer = new int[n + 1];

        words = br.readLine().split(" ");
        for (int i = 1; i <= n; ++i) {
            computer[i] = Integer.parseInt(words[i - 1]);
        }

        for (int i = 0; i < m; ++i) {
            words = br.readLine().split(" ");
            int a = Integer.parseInt(words[0]);
            int b = Integer.parseInt(words[1]);
            int c = Integer.parseInt(words[2]);
            int d = Integer.parseInt(words[3]);

            if (!list.isEmpty() && list.get(0)[0] <= a) {
                int idx = bSearch(a);
                for (int j = idx; j >= 0; --j) {
                    computer[list.get(j)[1]] += list.get(j)[2];
                    list.remove(j);
                }
            }

            if (d <= computer[b]) {
                computer[b] -= d;
                int idx;
                if (list.isEmpty() || list.get(0)[0] >= a + c) {
                    idx = -1;
                } else {
                    idx = bSearch(a + c);
                }
                list.add(idx + 1, new int[]{a + c, b, d});
//                System.out.println(computer[b]);
                wr.write(computer[b] + "\n");
            } else {
//                System.out.println(-1);
                wr.write(-1 + "\n");
            }
        }
    }
}